define(["dojo/_base/declare", "../BaseWidget",
        "dojo/_base/lang",
        "dojo/on",
        "dojo/topic",
        "esri/dijit/LayerSwipe",
        "dojo/_base/array",
        "dijit/registry",
        "dojo/query",
        "dojo/dom-style",
        "dojo/dom-class",
        "dojo/text!./templates/Template.html"],
        function(declare,BaseWidget,lang,on,topic,
        		LayerSwipe,array,registry,query,style,domClass,template) {
	return declare([BaseWidget], {
		//模板页面
		templateString : template,
		map:null,
		swipeLayers:[],//当前需进行卷帘对比的图层数组
		swipeWidget:null,//卷帘组件对象

		legendlist:null,
		legendnames:null,
		showlayerdiv:true,//图层选择框显示状态
		constructor : function(args) {
			this.inherited(arguments);
			this.map = args.map;//mapWidget.map;
		},
		//组件初始化方法
		postCreate : function() {
			this.inherited(arguments);
			//on(this.collsape, "click",lang.hitch(this,this.collsaple));//图层选择框收缩或展开按钮点击事件
			topic.subscribe("UpdateSwipeLayers",lang.hitch(this,this.selectLayerIDsHandler));//图层选中状态变化时，更新卷帘对比图层列表
			topic.subscribe("CloseSwipeLayers",lang.hitch(this,this.CloseSwipeLayers));//图层选中状态变化时，更新卷帘对比图层列表
			
		},
		destroy:function(){
			this.inherited(arguments);
			this.legendlist = [];
	        this.legendnames = "";
		},
		 startup:function(){
	        this.inherited(arguments);
	        this.legendlist = [];
	        this.legendnames = "";
		},
		initLayerListHandler:function(){//卷帘图层列表初始化
//			debugger;
			dojo.empty("legend");
			//获取地图上所有已加载的图层
			var legends = this.legendlist;
			var htmlstr ="";
			for(var i=0;i<legends.length;i++){
				var layerid = legends[i];
				htmlstr += "<tr><td ><div class='legendnode' style='background-color:"+layerid.color+"'/></td>" +
				               "<td >"+layerid.name+"</td>" +
				           "</tr>";
			}
			dojo.query("#legend").addContent(htmlstr);
		},
		resetLegend:function(){
			this.legendlist = [];
	        this.legendnames = "";
		},
		/**
         * 根据参数加载饼状图
         */
        initLegend:function(dimensionName,czldCount,gyjcydCount,sjjcCount,sjjtjcCount,sjjchCount,gysbydCount){

        	if(czldCount!=undefined && czldCount != ''&& czldCount != 0&&this.legendnames.indexOf("CUN")==-1){
        		this.legendlist.push({color:'#5DA5B8',name:'村自留地'});
        		this.legendnames += "#CUN#";
        	}
        	if(gyjcydCount!=undefined && gyjcydCount != ''&& gyjcydCount != 0&&this.legendnames.indexOf("GYJC")==-1){
 
        		this.legendlist.push({color:'#FDB961',name:'国有用地的旧厂'});
 
        		this.legendnames += "#GYJC#";
        	}
        	if(sjjcCount!=undefined && sjjcCount != '' && sjjcCount != 0&&this.legendnames.indexOf("SJJCUN")==-1){
        		this.legendlist.push({color:'#F36D6F',name:'三旧旧村'});
        		this.legendnames += "#SJJCUN#";
        	}
        	if(sjjtjcCount!=undefined && sjjtjcCount != ''&& sjjtjcCount != 0&&this.legendnames.indexOf("JTJC")==-1){
        		this.legendlist.push({color:'#F6A26D',name:'集体用地的旧厂'});
        		this.legendnames += "#JTJC#";
        	}
        	if(sjjchCount!=undefined && sjjchCount != ''&& sjjchCount != 0&&this.legendnames.indexOf("SJJCH")==-1){
        		this.legendlist.push({color:'#9E81B2',name:'三旧旧城'});
        		this.legendnames += "#SJJCH#";
        	}
        	if(gysbydCount!=undefined && gysbydCount != ''&& gysbydCount != 0&&this.legendnames.indexOf("GYCBYD")==-1){
        		this.legendlist.push({color:'#75C8B1',name:'国有储备用地'});
        		this.legendnames += "#GYCBYD#";
        	}
        	return this.legendlist;
        }
		
	});
});